package main

import (
	"fmt"
	"zinx/zinterface"
	"zinx/zserver"
)

type PingRouter struct {
	zserver.BaseRouter
}

func (pr *PingRouter) PreHandle(request zinterface.IRequest) {
	fmt.Println("Start Ping PreHandle")
	if _, err := request.GetConnection().GetTCPConnection().Write([]byte("Pre Ping...")); err != nil {
		fmt.Println("!!!ERROR When Pre Ping: ", err)
		return
	}
	fmt.Println("End Ping PreHandle")
}

func (pr *PingRouter) Handle(request zinterface.IRequest) {
	fmt.Println("Start Ping Handle")
	if _, err := request.GetConnection().GetTCPConnection().Write([]byte("Ping...Ping...Ping")); err != nil {
		fmt.Println("!!!ERROR When Ping...Ping...Ping: ", err)
		return
	}
	fmt.Println("End Ping Handle")
}

func (pr *PingRouter) PostHandle(request zinterface.IRequest) {
	fmt.Println("Start Post PreHandle")
	if _, err := request.GetConnection().GetTCPConnection().Write([]byte("Post Ping...")); err != nil {
		fmt.Println("!!!ERROR When Post Ping: ", err)
		return
	}
	fmt.Println("End Ping PostHandle")
}


func main() {
	zs := zserver.New("zserver")

	zs.AddRouter(&PingRouter{})

	zs.Serve()
}
